package com.rongshu.view.submitArticle.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.view.base.AdapterListener;
import com.rongshu.view.submitArticle.bean.LabelBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * created by zhengweis on 2019/2/14.
 * description：
 */
public class ArticleColumnAdapter extends RecyclerView.Adapter<ArticleColumnAdapter.ColumnViewHolder> {
    private List<LabelBean> list;
    private Context context;
    private AdapterListener listener;
    public ArticleColumnAdapter(Context context, List<LabelBean> list) {
        this.list = list;
        this.context = context;
    }

    public void setAdapterListener(AdapterListener listener){
        this.listener = listener;
    }

    @NonNull
    @Override
    public ColumnViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_article_column, viewGroup, false);
        return new ColumnViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ColumnViewHolder viewHolder, int position) {
        final LabelBean bean = list.get(position);
        viewHolder.columnName.setText(bean.getTitle());
        viewHolder.columnContent.setText("测试  测试  测试  测试...");
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null){
                    listener.callBack(bean);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public static class ColumnViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.column_logo)
        ImageView columnLogo;
        @BindView(R.id.column_name)
        TextView columnName;
        @BindView(R.id.column_content)
        TextView columnContent;

        public ColumnViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
